Skip to content

Conversation

@Jeffrey-Zutt
Copy link

@Jeffrey-Zutt Jeffrey-Zutt commented May 26, 2016

We have multiple redactor-editors on one page, and some (or all) of them are placed within a LI tag.
Whenever the user tries to add a table, the table is placed after the closing LI tag, and thus outside the editor.

The change makes the plugin check if the closest LI tag is within the editor.
If so, it places the table after it. If not, it places the table where the cursor is.

@dtdesign
Copy link

dtdesign commented May 26, 2016

Using if ($(current).closest('li', this.core.editor()).length !== 0) instead is enough as it limits the search inside Redactor.

Your proposed change first searches the closest list item and then checks if it is contained within Redactor (hint: there is also this.utils.isRedactorParent() for this), which is essentially the same as above but in reverse.

@Jeffrey-Zutt
Copy link
Author

Ah, your way is more efficient indeed!
if ($(current).closest('li', this.core.editor()).length !== 0) does not work though, because this.core.editor() returns a set of elements.

I've changed it into if ($(current).closest('li', this.core.editor().get(0)).length !== 0) which does work.

Let me know what you think!

@dtdesign
Copy link

My bad, it's been a while I used closest(), just did a quick check of the API docs and didn't notice it required a DOM element rather than a jQuery object; Your solution is correct.

@Jeffrey-Zutt
Copy link
Author

No worries ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants